/***********************************************************************
 * POJO Class :  DocD.java
 * Author:  Bill Vison
 * Purpose: Defines the Class SysResource
 ***********************************************************************/

package edu.gtcfla.km.model;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.vsg.biz.utils.InjectRepo;

import edu.gtcfla.km.Category;
import edu.gtcfla.km.repositories.CategoryRepo;

@javax.persistence.Entity
@javax.persistence.Table(name = "CATEGORY")
public class CategoryD implements Category, java.io.Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -1L;

	@Column(name ="CATEGORY_ID")
	@GeneratedValue(generator = "paymentableGenerator")      
	@GenericGenerator(name = "paymentableGenerator", strategy = "uuid") 	
	@Id	
	private String id;	
	
	@Override
	public String getId() {
		// TODO Auto-generated method stub
		return id;
	}

	@Override
	public void setId(String id) {
		// TODO Auto-generated method stub
		this.id = id ;
	}

	@Column(name ="CATEGORY_NAME")	
	private String name;
	
	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return name;
	}

	@Override
	public void setName(String name) {
		// TODO Auto-generated method stub
		this.name = name;
	}
	
	
	@InjectRepo
	@Transient	
	private CategoryRepo categoryRepo;

	
	
	public CategoryRepo getCategoryRepo() {
		return categoryRepo;
	}

	public void setCategoryRepo(CategoryRepo categoryRepo) {
		this.categoryRepo = categoryRepo;
	}

	@OneToOne(cascade = javax.persistence.CascadeType.ALL)
	@JoinColumn(name="parent_id")
	private CategoryD parentD;

	public CategoryD getParentD() {
		return parentD;
	}

	public void setParentD(CategoryD parentD) {
		this.parentD = parentD;
	}

	@Override
	public Category getParent() {
		// TODO Auto-generated method stub
		Category cate = this.getParentD();
		
		try {
			if (cate != null) {
				cate.getId();
			}
		} catch (org.hibernate.LazyInitializationException lie) {
			
			cate = categoryRepo.findParent( this.id );

		}
				
		
		return cate;
	}

	@Override
	public void setParent(Category parent) {
		// TODO Auto-generated method stub
		if ( parent instanceof CategoryD) {
			this.setParentD( (CategoryD)parent );
		}
	}
	
	@Column(name ="CREATE_USER_ID")	
	private String createdUserId;

	@Override
	public String getCreatedUserId() {
		// TODO Auto-generated method stub
		return createdUserId;
	}

	@Override
	public void setCreatedUserId(String createdUserId) {
		// TODO Auto-generated method stub
		this.createdUserId = createdUserId;
	}
	
	@Column(name ="CREATED_DATE")	
	private Date createdDate;

	@Override
	public Date getCreatedDate() {
		// TODO Auto-generated method stub
		return this.createdDate;
	}

	@Override
	public void setCreatedDate(Date createdDate) {
		// TODO Auto-generated method stub
		this.createdDate = createdDate;
	}
	

	



	
	
	
}